<?php

class Control_Gm_setConfigAjax
{
    function setConfigAjax()
    {

        $file = MooForm::post('file');
        $serverIdArr = explode(',',trim(MooForm::post('serverIds'),','));

        $fileName = $file.'.xml';
        $configDir = ROOT_PATH . "/gamexml/";
        $fullDir = $configDir.$fileName;
        $file_path = $fullDir;
        if(file_exists($file_path)){
            $fileContent  = urlencode(file_get_contents($file_path));//将整个文件内容读入到一个字符串中
        }
        /*if(empty($fileContent)){
            $resData = array('code'=>-1,'message'=>'文件内容为空','data'=>'');
            $rs = MooJson::encode($resData);
            exit($rs);
        }*/


        $params = '?user=wow&name:$fileName;content:'.$fileContent; //name:aaa;content:xxx
        $data = array();
        foreach ($serverIdArr as $server){
            $sendUrl = 'http://'.$server.':10011/updateXml';
            $sendUrl .= $params;
            $res = MooUtil::curl_request($sendUrl);
            $data[] = $sendUrl;
        }

        $resData = array('code'=>0,'message'=>'success','data'=>$data);
        $rs = MooJson::encode($resData);
        exit($rs);

    }

}